// eventBus.js
import { createApp } from 'vue';

const app = createApp({});
export const eventBus = app.config.globalProperties;

// 添加自定义事件方法
eventBus.$on = function(eventName, callback) {
    this._eventBusListeners = this._eventBusListeners || {};
    if (!this._eventBusListeners[eventName]) {
        this._eventBusListeners[eventName] = [];
    }
    this._eventBusListeners[eventName].push(callback);
};

eventBus.$emit = function(eventName, ...args) {
    const listeners = this._eventBusListeners && this._eventBusListeners[eventName];
    if (listeners) {
        listeners.forEach(callback => callback(...args));
    }
};